﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using TaskManagement.ModelLayer;

namespace TaskManagement.BusinessLayer
{
    public class WorkflowControler
    {
        private IDBWorkflow dbWorkflow;

        public WorkflowControler()
        {
            dbWorkflow = new DBWorkflow();
        }

        public List<Workflow> SearchWorkflows(Workflow w)
        {
            return dbWorkflow.SearchWorkflows(w);
        }

        public int CreateWorkflow(Workflow w)
        {
            return dbWorkflow.CreateWorkflow(w);
        }

        public string UpdateWorkflow(Workflow w)
        {
            string result = "";

            if(dbWorkflow.CheckTaskDates(w))
            {
                result = "Cannot update workflow with a startdate that is after the date of one of its tasks";
            }
            else
            {
                result = dbWorkflow.UpdateWorkflow(w).ToString();
            }

            return result;
        }

        public int DeleteWorkflows(IList<Workflow> workflows)
        {
            return dbWorkflow.DeleteWorkflow(workflows);
        }
    }
}
